/**
 * @class   wosh::building::DoorBell
 * @brief   BuildingObject representing a generic (real) door bell.
 *          This class provides standard Methods and properties to 
 *          control the the mapped wosh::interfaces::devices::Switch
 *
 ****************************************************************************
 * @version 0.8.399 $Id: DoorBell.h 2863 2010-08-07 04:28:58Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Building_DoorBell_H__
 #define __WOSH_Building_DoorBell_H__

 #include <framework/building/BuildingObject.h>


namespace wosh {
 namespace building {

 #define _DoorBell_VERSION					0.8399

 #define _DoorBell_METHOD_mute				"mute"
 #define _DoorBell_METHOD_test				"test"

 #define _Door_EVENT_DoorBellRinging		"DoorBellRinging"


class DoorBell : public BuildingObject
 {
	WOSH_BUILDINGOBJECT(wosh::building::DoorBell)

	public:
		/**
		 * @brief   bell states
		 */
		enum BELL_STATE {
			BELL_UNKNOWN	= 0x00,	///< bell state is unknown
			BELL_IDLE		= 0x01,	///< bell is idel (off, normal state)
			BELL_RINGING	= 0x02	///< bell is ringing now
		};

	public:
		/**
		 * @brief  Empty constructor.
		 */
		DoorBell();
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		DoorBell( const DoorBell& m ) : BuildingObject(m) { }
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~DoorBell() { }


	public:
		virtual void busMessageChild( const Message& message );

//@}
/** @name DoorBell Interface - 
 * @{
 ******************************************************************************/
	public:
		WRESULT mute();
		WRESULT test();

	public:
		/**
		 * @brief   Get last known door-bell state (opened, closed, unknown)
		 * @return  current door-bell state (enum)
		 */
		DoorBell::BELL_STATE getState() const			{ return this->state; }
		/**
		 * @brief   Get door-bell state as a literal string
		 * @return  current door-bell state as literal string
		 */
		inline const char* getStateAsString() const		{ return getStateAsString(this->state); }
		/**
		 * @brief   Get door-bell state as a literal string
		 * @param state [in] door-bell state to be retrieved as literal string
		 * @return  passed door-bell state as literal string
		 */
		static const char* getStateAsString( DoorBell::BELL_STATE state );
		/**
		 * @brief   Get door-bell state from a literal string
		 * @param state [in] door-bell state as literal string
		 * @return  door-bell state (as enum) associated with the argument 
		 */
		static DoorBell::BELL_STATE getStateFromString( const char* state );

//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual bool updateHash( DataHashContext* hash_context ) const;
//@}
	protected:
		virtual void init();
		void setState( DoorBell::BELL_STATE state, bool raiseEvent = true, const SecurityToken* source_token = NULL );

	protected:
		DoorBell::BELL_STATE state;	///< current state


}; // class def



/**
 * @class   wosh::building::Door_StateChanged
 * @brief   Raised when door state is changed (such as open to closed).
 *
 * Internally, data is stored as wosh::List. Supports also wosh::Variant type.
 *
 * Fields are:
 *  - \c door_state [Variant::INTEGER] (always present, first item of the list)
 *  - \c previous_door_state (optional, second item of the list)
 *
 * Some getters are provided for convenience:
 * \code

 * \endcode
 *
 * @see     wosh::Fact
 * @see     wosh::building:DoorBell
 ****************************************************************************
 * @version 0.8.399 $Id: DoorBell.h 2863 2010-08-07 04:28:58Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
class DoorBell_Ringing : public wosh::Fact
 {
	WOSH_SERIALIZABLE(wosh::building::DoorBell_Ringing)

	public:
		/**
		 * @brief  Empty constructor.
		 */
		DoorBell_Ringing()
			: wosh::Fact(_Door_EVENT_DoorBellRinging) { }
		/**
		 * @brief  Constructor with initializers.
		 * @param current_doorbell_state [in] current state of the doorbell
		 */
		DoorBell_Ringing( DoorBell::BELL_STATE current_doorbell_state );
		/**
		 * @brief  Constructor with initializers.
		 * @param bell [in] current state of the doorbell
		 * @param previous_doorbell_state [in] previous state of the doorbell
		 */
		DoorBell_Ringing( DoorBell::BELL_STATE current_doorbell_state, DoorBell::BELL_STATE previous_doorbell_state );
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		DoorBell_Ringing( const DoorBell_Ringing& m )
			: wosh::Fact(m) { }
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~DoorBell_Ringing() { }

	public:
		/**
		 * @brief   Get doorbell state (opened, closed, unknown)
		 * @return  current doorbell state (enum)
		 */
		DoorBell::BELL_STATE getDoorBellState() const;

		/**
		 * @brief   Get previous doorbell state (opened, closed, unknown)
		 * @return  previous doorbell state (enum)
		 */
		DoorBell::BELL_STATE getPreviousDoorBellState() const;

	public:
		inline bool isRinging() const {
			return ( getDoorBellState() == DoorBell::BELL_RINGING );
		 }
		inline bool isIdle() const {
			return ( getDoorBellState() == DoorBell::BELL_IDLE );
		 }


}; // class def



 }; // namespace building
}; // namespace wosh

#endif //__WOSH_Building_DoorBell_H__
